package spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

@Controller
@RequestMapping("/post/raw")
public class PostRawController {

    // curl -i --data "{a:b,c:d}" localhost:8080/post/raw
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public String authority(HttpServletRequest req, HttpServletResponse res) throws IOException {

        // 获取raw数据 上送的的数据是如下，不是表单 a=b&c=d
//        {
//             "email": "abc",
//             "password": "xyz",
//             "deviceId": "gogo"
//        }
        System.out.println("AuthController2");
        System.out.println("req=" + req);
        InputStream inputStream = req.getInputStream();
        String str = IOUtils.stream2String(inputStream, "utf-8");
        System.out.println("str = " + str); // ok
        return "abc";
    }
}
